package com.cuitrip.business.comment;

import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.cuitrip.apiservice.OrderBusiness;
import com.cuitrip.apiservice.model.ApiManager;
import com.cuitrip.business.comment.model.Comment;
import com.cuitrip.business.order.model.OrderItem;
import com.cuitrip.service.R;
import com.cuitrip.util.ResourceUtil;
import com.lab.app.customui.CustomUiConfig;
import com.lab.app.customui.CustomUiFragmentActivity;
import com.lab.network.model.CtApiResponse;
import com.lab.network.model.IProxyCallback;
import com.lab.network.model.ProxyResult;
import com.lab.network.proxy.ApiProxy;
import com.lab.utils.Utils;
import com.lab.widget.WordCountView;

import butterknife.ButterKnife;
import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by sheena on 16/1/20.
 */
public class FeedBackActivity extends CustomUiFragmentActivity implements IProxyCallback{

    @Bind(R.id.skip)
    TextView skipButton;

    @Bind(R.id.wcv_feedback)
    WordCountView wcvFeedback;

    @Bind(R.id.tv_desc)
    TextView tvDesc;

    @Bind(R.id.send)
    TextView btnSend;

    //private OrderItem mOrderInfo;
    private int score;
    private ApiProxy mApiProxy=new ApiProxy(this);
    private Comment comment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Intent intent = getIntent();
        comment = (Comment) intent.getSerializableExtra(NPSRateActivity.COMMENT_KEY);
        score = intent.getIntExtra(NPSRateActivity.NPS_SCORE, -1);
        super.onCreate(savedInstanceState, R.layout.activity_feedback);
    }

    @Override
    public void initView() {
        ButterKnife.bind(this);
        skipButton.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        skipButton.getPaint().setAntiAlias(true);
    }

    @OnClick(R.id.skip)
    public void skip2CommentSuc(){
        Intent intent=new Intent(FeedBackActivity.this,CommentSuccessActivity.class).putExtra(NPSRateActivity.COMMENT_KEY,comment).putExtra(NPSRateActivity.NPS_SCORE, score);
        startActivity(intent);
    }

    @OnClick(R.id.send)
    public void sendFeedback(){
        if (TextUtils.isEmpty(wcvFeedback.getEditView().getText())){
            Utils.shakeView(wcvFeedback);
        }else{
            String feedback = wcvFeedback.getContent();
            showLoading();
            OrderBusiness.submitNPS(mApiProxy, score, "1", feedback);
        }
    }

    @Override
    public void initData() {
        tvDesc.setText(getString(R.string.review_nps_feedback,score));
        wcvFeedback.getCountView().setTextColor(ResourceUtil.getColor(R.color.ganshi_ded8d7));
        wcvFeedback.getEditView().setHintTextColor(ResourceUtil.getColor(R.color.ganshi_ded8d7));
    }


    @Override
    public boolean initCloseTopBar() {
        return true;
    }

    @Override
    public CustomUiConfig initCustomUiConfig() {
        return null;
    }


    @Override
    public boolean onProxyResult(ProxyResult<?> result) {
        CtApiResponse response = (CtApiResponse) result.getData();
        hideLoading();
        if (ApiManager.SUBMIT_NPS_INFO.equals(response.getApiName())) {
            skip2CommentSuc();
        }
        return false;
    }
}
